﻿using AccustomeAttributedll;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using FinalTestMachine.Motion;
using FinalTestMachine.Motion.Aixs;

namespace FinalTestMachine.View
{
    /// <summary>
    /// Wnd_Motion.xaml 的交互逻辑
    /// </summary>
    public partial class Wnd_Motion : Window
    {
        static Wnd_Motion Cur = null;
        static readonly object ob_lock = new object();
        private Wnd_Motion()
        {
            InitializeComponent();
        }

        public static Wnd_Motion CreateInstrance()
        {
            if (Cur == null)
            {
                lock (ob_lock)
                {
                    if (Cur == null)
                    {
                        Cur = new Wnd_Motion();
                    }
                }
            }
            return Cur;
        }

        public static void SingleShow()
        {
            Wnd_Motion wnd_Motio = CreateInstrance();
            wnd_Motio.WindowState = WindowState.Normal;
            IUserLimitdll.PreControlBindingHelper.SetLitmitBinding(wnd_Motio, IUserLimitdll.UserLevelModes.ModifyAndOperation);
            wnd_Motio.Show();
            wnd_Motio.Focus();

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            MotionWndViewModelHelper motionWindowViewModel = MotionWndViewModelHelper.CreateInstrance();

            //绑定内容控件
            Binding binding = new Binding("UserControlCurShow") { Source = motionWindowViewModel };
            Motion_Content.SetBinding(ContentProperty, binding);

            //创建按钮列表
           
            foreach (var vr in motionWindowViewModel.unit_UserViewModelsList)
            {
                Motion_SwitchBtns.Children.Add(vr.button);

            }
            this.Closed += delegate
            {
                Motion_SwitchBtns.Children.Clear();
            };
          
        }

        private void Window_Closed(object sender, EventArgs e)
        {
            MotionWndViewModelHelper motionWindowViewModel = MotionWndViewModelHelper.CreateInstrance();
           
            Cur = null;
        }
        RM_dll2.MotionHelper Motion => StaticInitial.Motion;

      
    }
}
